package com.bp.hearthealth.pulse.lnapps.bp_ui.bp_fragment.bp_lifestyle.bp_adapter

import android.annotation.SuppressLint
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.bp.hearthealth.pulse.lnapps.bp_ui.bp_fragment.bp_lifestyle.bp_bean.BpLifeStyleBean
import com.bp.hearthealth.pulse.lnapps.bp_ui.bp_fragment.bp_lifestyle.bp_fragment.BpLifeStyleArticelFragment
import com.bp.hearthealth.pulse.lnapps.bp_ui.bp_fragment.bp_lifestyle.bp_fragment.BpLifeStyleWebViewFragment

class BpLifeStylePagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {

    private val modelList = mutableListOf<MutableList<BpLifeStyleBean>>()

    @SuppressLint("NotifyDataSetChanged")
    fun updateFragments(fragmentList: MutableList<MutableList<BpLifeStyleBean>>) {
        modelList.clear()
        modelList.addAll(fragmentList)
        notifyDataSetChanged()
    }

    override fun getItemCount(): Int {
        return modelList.size
    }

    override fun createFragment(position: Int): Fragment {
//        if (position == 0) {
//            return BpLifeStyleWebViewFragment()
//        }
        return BpLifeStyleArticelFragment.newInstance(modelList[position])
    }
}
